﻿
using Interface;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlowerDAL
{
    public class UsersDAL : IUsers
    {
        #region 登录方法
        public T Login<T>(string phone, string pwd)
        {
            return DBHelper.Login<T>(phone, pwd);
        }
        #endregion

        #region 注册
        /// <summary>
        /// 注册方法
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Register<T>(T t)
        {
            string filed = "";
            string value = "";
            Type type = typeof(T);
            foreach (var item in t.GetType().GetProperties())
            {
                if (item.Name == "Id")
                    continue;

                filed += item.Name + ",";

                if (item.PropertyType == typeof(string) || item.PropertyType == typeof(DateTime))
                {
                    value += "'" + item.GetValue(t) + "',";
                }
                else
                    if (item.PropertyType == typeof(int) || item.PropertyType == typeof(decimal))
                    {
                        value += item.GetValue(t) + ",";
                    }
            }

            filed = filed.TrimEnd(',');
            value = value.TrimEnd(',');

            string sql = "insert into " + type.FullName + " (" + filed + ") values(" + value + ")";
            return DBHelper.ExecuteNonQuery(sql);
        }

        #endregion

        #region 判断手机号是否存在
        public int IsPhone<T>(string phone)
        {
            return DBHelper.IsPhone<T>(phone);
        }
        #endregion






       
    }
}
